import request from '@/utils/request.js'

/**
 * 换取openid
 */
export function getOpenid (jsCode) {
	return request.get({
		url: `/users/weixin?jsCode=${jsCode}`
	})
}

/**
 * 判断是否注册过
 */
export function hasRegistered (openid) {
	return request.post({
		url: `/users/hasRegistered`,
		data: {
			openId: openid
		}
	})
}

/**
 * 注册
 */
export function register (data) {
	return request.post({
		url: '/users/register',
		data
	})
}

/**
 * 登录
 */
export function login (openid) {
	return request.post({
		url: `/users/login`,
		data: {
			openId: openid
		}
	})
}

/**
 * 微信code换手机号
 */
export function getPhoneByCode (code) {
	return request.get({
		url: `/users/getWeixinUserPhone/${code}`
	})
}

/**
 * 更新用户信息
 */
export function updateUserInfoById ({ avatar, username, phone }) {
	return request.post({
		url: `/users/updateUser`,
		data: {
			avatar, 
			username, 
			phone
		}
	})
}

/**
 * 查询用户信息
 */
export function getInfo () {
	return request.get({
		url: `/users/info`
	})
}